package com.dfbz.dao;

import com.dfbz.entity.Dept;
import org.springframework.jdbc.core.BeanPropertyRowMapper;

import java.util.List;
import java.util.Map;

public class DeptDao extends baseDao{
    public List<Map<String, Object>> findAll() {
        String sql="SELECT\n" +
                "\td.*,\n" +
                "\tcount( u.dept_id ) deptCount \n" +
                "FROM\n" +
                "\tdept d\n" +
                "\tLEFT JOIN USER u ON d.id = u.dept_id \n" +
                "GROUP BY\n" +
                "\td.id";
        return jdbcTemplate.queryForList(sql);
    }

    public List<Dept> findAlldept() {
        return jdbcTemplate.query("SELECT * from dept",new BeanPropertyRowMapper<>(Dept.class));
    }

    public Dept findByID(Long deptId) {
        return jdbcTemplate.queryForObject("SELECT * from dept where id=?",new BeanPropertyRowMapper<>(Dept.class),deptId);
    }
}
